package com.ruoyi.controller.jpjs.costsettlement;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.service.jpjs.costsettlement.CostSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/costSettlement")
public class CostSettlementController extends BaseController {

    @Autowired
    private CostSettlementService costSettlementService;

    private String prefix = "jpjs/costsettlement";

    @GetMapping()
    public String list(ModelMap mmp) {
        mmp.put("fillFlag",costSettlementService.findUserFill());
        return prefix + "/CostSettlement";
    }

    @GetMapping("/select")
    public String select(ModelMap mmp) {
        return prefix + "/CostSettlementSelect";
    }

    @PostMapping("/select")
    @ResponseBody
    public TableDataInfo select(@RequestParam Map<String, Object> map) {
        return getDataTable(costSettlementService.findSettlementSelectAll(map));
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        return getDataTable(costSettlementService.findSettlementAll(map));
    }

    @GetMapping("add")
    public String add() {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map<String, Object> map) {
        return toAjax(costSettlementService.add(map));
    }

    @GetMapping("edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmp) {
        mmp.put("settlement", costSettlementService.findSettlement(id));
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map<String, Object> map) {
        return toAjax(costSettlementService.editInfo(map));
    }

    @PostMapping("remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") Integer id) {
        return toAjax(costSettlementService.deleteInfo(id));
    }

    @GetMapping("submitUser")
    public String submitUser(@RequestParam Integer id, ModelMap mmp) {
        mmp.put("id", id);
        mmp.put("submitUser", costSettlementService.findSubmitUser());
        return prefix + "/submitUser";
    }

    @PostMapping("/submitUser")
    @ResponseBody
    public AjaxResult submitUser(@RequestParam Map<String, Object> map) {
        return toAjax(costSettlementService.editSubmit(map));
    }

    @GetMapping("/submitFinal")
    @ResponseBody
    public AjaxResult submitFinal(@RequestParam Integer id) {
        return toAjax(costSettlementService.editSubmitFinal(id));
    }

    @GetMapping("approval")
    public String approval(@RequestParam Integer id, ModelMap mmp) {
        mmp.put("settlement", costSettlementService.findSettlement(id));
        return prefix + "/approval";
    }

    @PostMapping("/approval")
    @ResponseBody
    public AjaxResult approval(@RequestParam Map<String, Object> map) {
        return toAjax(costSettlementService.editApproval(map));
    }

    @GetMapping("/isFiled")
    @ResponseBody
    public AjaxResult isFiled(@RequestParam Integer id) {
        return toAjax(costSettlementService.editFiled(id));
    }

    @PostMapping("/createNumber")
    @ResponseBody
    public String createNumber(@RequestParam Map<String, Object> map) {
        return costSettlementService.createNumber(map);
    }

    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String, Object> map) {
        return costSettlementService.export(map);
    }
}
